package com.example.dllo.exe.fenlei.xuanlishenqi;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.bean.PopupWindowPinJieBean;
import com.example.dllo.exe.fengzhuang.NetTool;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class PopupWindowPinJieAdapter extends RecyclerView.Adapter<PopupWindowPinJieAdapter.MyViewHolder>{
    private Context context;
    private PopupWindowPinJieBean popupWindowPinJieBean;

    public void setPopupWindowPinJieBean(PopupWindowPinJieBean popupWindowPinJieBean) {
        this.popupWindowPinJieBean = popupWindowPinJieBean;
        notifyDataSetChanged();
    }

    public PopupWindowPinJieAdapter(Context context) {
        this.context = context;
    }

    @Override
    public PopupWindowPinJieAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.remenfragmentrvlayout, parent, false);


        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(PopupWindowPinJieAdapter.MyViewHolder holder, int position) {
       holder.nametext.setText(popupWindowPinJieBean.getData().getItems().get(position).getName());
        holder.pricetext.setText(popupWindowPinJieBean.getData().getItems().get(position).getPrice());
        holder.favoritestext.setText(popupWindowPinJieBean.getData().getItems().get(position).getFavorites_count()+"");
        NetTool netTool=new NetTool();
        netTool.getImage(popupWindowPinJieBean.getData().getItems().get(position).getCover_image_url(),holder.imageImgurl);
    }

    @Override
    public int getItemCount() {
        return popupWindowPinJieBean!=null?popupWindowPinJieBean.getData().getItems().size():0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nametext;
        TextView pricetext;
        TextView favoritestext;
        ImageView imageImgurl;
        public MyViewHolder(View itemView) {
            super(itemView);
            nametext = (TextView) itemView.findViewById(R.id.Name_ReMen);
            pricetext = (TextView) itemView.findViewById(R.id.Price_ReMen);
            imageImgurl = (ImageView) itemView.findViewById(R.id.Image_ReMen);
            favoritestext = (TextView) itemView.findViewById(R.id.Favorites_ReMen);
        }
    }
}

